#pragma once
#include "Math2D.h"
#include <XInput.h>

//	Global input state, set by window events.
//	Accumulated until requested but not queued.

namespace Input
{
//+==================================================================+
struct KeyboardState
{
	DWORD	LastKey,								// wParam = virtual key code
			LastPar;								// lParam = parameter, e.g. bit 24 = extended flag
	bool	LastExt;								// whether the last pressed key was an extended key
	bool	Escape,								// VK_ESCAPE
			Return,								// VK_RETURN
			Space,								// VK_SPACE
			Back,									// VK_BACK
			Up,									// VK_UP
			Down,									// VK_DOWN
			Left,									// VK_LEFT
			Right,								// VK_RIGHT
			Multiply,
			Add,
			Subtract,
			Divide;
//			F1,F2,F3,F4;						// FK_F1...
};

//+==================================================================+
struct MouseState
{
	bool	LButton,
			RButton,
			ScrollUp,
			ScrollDown;
};

//+==================================================================+
struct PadState
{
//----
//	raw state
	XINPUT_STATE		State;

//----
// button "presses", i.e., only triggered once until released again
	bool					A, B, X, Y, L, R,
							D_Up, D_Down, D_Left, D_Right,
							Start, Back;
//----
// "normalized" and deadzone removed thumbsticks, i.e., between (-1,1)
	Vector2D<double>	LThumb, RThumb;
};

//+------------------------------------------------------------------+
extern KeyboardState	Key;
extern MouseState		Mouse;
extern PadState		Pad;
extern bool				UsingPad;			// was the gamepad rescently used?

//+------------------------------------------------------------------+
//	Copies state into provided structures, and resets internal state.
void GetAndReset(KeyboardState *key = NULL, MouseState *mouse = NULL, PadState *pad = NULL);

//+------------------------------------------------------------------+
bool HandleMouseEvent(MSG &msg);

//+------------------------------------------------------------------+
bool HandleKeyEvent(MSG &msg);

//+------------------------------------------------------------------+
void UpdateXInput();


}//namespace Input


